home *** CD-ROM | disk | FTP | other *** search
- //
- // Generic Attack AI file
- //
- // Behaviors:
- //
- // When idle, periodically look for an enemy unit to attack.
- // Attempt to keep target in weapon range by moving and/or facing when target moves.
- // Return to idle state when target dies or moves out of LOS.
- //
- // Notes:
- //
- // When using this file with the Generic Movement AI file, you should include this file first.
- // Failure to do so will result in units that don't stop when in weapon range or when
- // their target dies. Your unit will look stupid.
- //
- // Common modifications:
- //
- // To abort the attack early with a new trigger, insert a new AttackEnemyUnit and
- // FaceEnemyUnit transition specification before including this file.
- // To prevent pursuit of fleeing enemies, place new FaceEnemyUnit:UnitNotInWeaponRange
- // and AttackEnemyUnit:UnitNotInWeaponRange transition specifications after
- // including this file.
- // To prevent following a faster target, place a new ReacquireGoal:GoalIsUnit transition
- // specification after including this file.
- //
- // Known Problems:
- //
- // Usage:
- //
- // To tell a unit to attack another unit, give it an attack goal (EEUGAttackUnit or EEUGAttackGround)
- // and set it's action to keeuaAttackEnemyUnit.
- //
-
- // any good targets around?
- Idle
- {
- CanISeeEnemy true(CheckRange)
- // we no longer poll to see if we're under attack - notification comes from EEUnit::TakeDamage()
- }
-
- // is the target in weapon range already?
- CheckRange
- {
- anyof(EnemyUnitDestroyed,CeaseFire,UnitNotOnMap,EnemyWithinMinimumRange) true(ShouldIReturnToInitialContactLocation)
- allof(EnemyUnitNoLongerVisible,GoalIsNotPlayerInitiated) true(ShouldIReturnToInitialContactLocation)
- UnitInWeaponRange true(FaceEnemyUnit)
- anyof(CanIMoveFreely,GoalIsPlayerInitiated) true(ShouldIFollowEnemyUnit) false(ShouldIReturnToInitialContactLocation)
- }
-
- // stop moving toward the target if we achieve weapon range
- GetNextMoveWaypoint
- {
- anyof(EnemyUnitDestroyed,CeaseFire) true(ShouldIReturnToInitialContactLocation)
- allof(AttackerIsRangedUnit,UnitInWeaponRange) true(FaceEnemyUnit)
- EnemyUnitMoved true(CheckRange)
- }
-
- // should I follow the enemy unit?
- ShouldIFollowEnemyUnit
- {
- allof(OneWaypointRemaining,GoalIsUnit,EnemyUnitHasNotMovedOneTile) true(Advance)
- anyof(CanIPursuePastInitialContactLOS,EnemyInsideInitialContactLOS,GoalIsPlayerInitiated) true(PrepareToMove) false(ShouldIReturnToInitialContactLocation)
- }
-
- // face our target until it is destroyed or moves
- FaceEnemyUnit
- {
- ShouldIRun true(RunFromAttacker)
- anyof(EnemyUnitDestroyed,CeaseFire,UnitNotOnMap,EnemyWithinMinimumRange) true(ShouldIReturnToInitialContactLocation)
- allof(EnemyUnitNoLongerVisible,GoalIsNotPlayerInitiated) true(ShouldIReturnToInitialContactLocation)
- UnitInWeaponRange false(CheckRange)
- allof(TargetIsSpecialEnemy,Reloaded,EnemyUnitInsideFiringArch) true(ChangeTargetForSpecialEnemy)
- allof(Reloaded,EnemyUnitInsideFiringArch) true(AttackEnemyUnit)
- FacingEnemyUnit true(WaitForReload)
- }
-
- ChangeTargetForSpecialEnemy
- {
- AlwaysTrue true(ReacquireGoal)
- }
-
- // attack the target until it is destroyed or moves
- AttackEnemyUnit
- {
- ShouldIRun true(RunFromAttacker)
- ShouldIRetaliate true(RetaliateAgainstAttacker)
- EnemyUnitInsideFiringArch false(FaceEnemyUnit)
- AlwaysTrue true(WaitForReload)
- }
-
-
- // face our target until it is destroyed or moves
- FaceLocation
- {
- ShouldIRun true(RunFromAttacker)
- ShouldIRetaliate true(RetaliateAgainstAttacker)
- CeaseFire true(Idle)
- LocationInWeaponRange false(PrepareToMove)
- LocationInsideFiringArch true(WaitForReload)
- }
-
- // wait for reload - this guarentees that we get at least 1 attack off
- WaitForReload
- {
- ShouldIRun true(RunFromAttacker)
- ShouldIRetaliate true(RetaliateAgainstAttacker)
- Reloaded true(FaceEnemyUnit)
- anyof(EnemyUnitDestroyed,CeaseFire,UnitNotOnMap,EnemyWithinMinimumRange) true(ShouldIReturnToInitialContactLocation)
- allof(EnemyUnitNoLongerVisible,GoalIsNotPlayerInitiated) true(ShouldIReturnToInitialContactLocation)
- }
-
- // attack the target until it is destroyed or moves
- InitialAttackState
- {
- //Reloaded false(WaitForReload)
- GoalIsUnit true(FaceEnemyUnit)
- }
-
- // ReAcquire Goal
- // BlockedByWall needs to come first
- // Followed by the tests for the various possible goals
-
- ReacquireGoal
- {
- BlockedByWall true(ShouldIReturnToInitialContactLocation)
- GoalIsUnit true(ReacquireEnemyUnit)
- }
-
- ReacquireEnemyUnit
- {
- EnemyUnitReachable true(CheckRange) false(ShouldIReturnToInitialContactLocation)
- }
-
- RetaliateAgainstAttacker
- {
- GoalIsUnit true(CheckRange) false(PrepareToMove)
- }
-
- RunFromAttacker
- {
- AlwaysTrue true(PrepareToMove)
- }
-
- UnderAttack
- {
- CanFlee true(RunFromAttacker)
- allof(CanITargetEnemies,UnitIdleOrAttackingDefenselessBuilding,IsAttackerInRetaliationRange,CanDamageAttacker,AttackerIsReachable) true(RetaliateAgainstAttacker) false(ReacquireGoal)
- }
-